//*********************************************************
//
//    Copyright (c) Microsoft. All rights reserved.
//    This code is licensed under the Apache License, Version 2.0.
//    THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
//    ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
//    IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
//    PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
//*********************************************************

namespace Microsoft.Research.eResearch.Blackboard.Wcf
{
    using System;
    using System.ServiceModel;
    using Microsoft.Research.eResearch.Blackboard.Common;

    /// <summary>
    /// Provides the service implementation of the <see cref="IWcfNotificationSubscriptionService"/> interface.
    /// </summary>
    [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall, ConcurrencyMode = ConcurrencyMode.Multiple)]
    public class WcfNotificationSubscriptionService : IWcfNotificationSubscriptionService
    {
        /// <summary>
        /// Subscribes the specified return address of the subscriber with the specified subscription profile.
        /// </summary>
        /// <param name="returnAddress">The return address of the subscriber.</param>
        /// <param name="profile">The subscription profile.</param>
        public void Subscribe(Uri returnAddress, SubscriptionProfile profile)
        {
            NotificationSubscriptionReceiverExtension ext =
                OperationContext.Current.Host.Extensions.Find<NotificationSubscriptionReceiverExtension>();
            ext.Subscribe(returnAddress, profile);
        }

        /// <summary>
        /// Unsubscribes the specified return address of the subscriber.
        /// </summary>
        /// <param name="returnAddress">The return address of the subscriber.</param>
        public void Unsubscribe(Uri returnAddress)
        {
            NotificationSubscriptionReceiverExtension ext =
                OperationContext.Current.Host.Extensions.Find<NotificationSubscriptionReceiverExtension>();
            ext.Unsubscribe(returnAddress);
        }
    }
}
